From 6bedce0c5d053ecddc4e3a0ba6812a3bd8360761 Mon Sep 17 00:00:00 2001 From: "iap10@freefall.cl.cam.ac.uk" Date: Wed, 9 Feb 2005 18:57:13 +0000 Subject: [PATCH] bitkeeper revision 1.1159.257.1 (420a5d09baXJPJiifdfGaELY297KOw) Refactor code to eliminate some code duplication. - added gva_to_gpte - gva_to_gpa uses gva_to_gpte now Signed-off-by: Arun Sharma Signed-off-by: ian.pratt@cl.cam.ac.uk --- xen/arch/x86/vmx.c | 60 +++--------------------------- xen/arch/x86/vmx_platform.c | 11 ++---- xen/include/asm-x86/shadow.h | 35 +++++++++++++++++ xen/include/asm-x86/vmx_platform.h | 2 +- 4 files changed, 44 insertions(+), 64 deletions(-) diff --git a/xen/arch/x86/vmx.c b/xen/arch/x86/vmx.c index 70e669183f..01bc372041 100644 --- a/xen/arch/x86/vmx.c +++ b/xen/arch/x86/vmx.c @@ -109,11 +109,9 @@ static void inline __update_guest_eip(unsigned long inst_len) static int vmx_do_page_fault(unsigned long va, unsigned long error_code) { - unsigned long eip, pfn; - unsigned int index; - unsigned long gpde = 0, gpte, gpa; + unsigned long eip; + unsigned long gpa; int result; - struct exec_domain *ed = current; #if VMX_DEBUG { @@ -123,32 +121,13 @@ static int vmx_do_page_fault(unsigned long va, unsigned long error_code) va, eip, error_code); } #endif - /* - * Set up guest page directory cache to make linear_pt_table[] work. - */ - __guest_get_l2e(ed, va, &gpde); - if (!(gpde & _PAGE_PRESENT)) - return 0; - - index = (va >> L2_PAGETABLE_SHIFT); - if (!l2_pgentry_val(ed->arch.guest_pl2e_cache[index])) { - pfn = phys_to_machine_mapping(gpde >> PAGE_SHIFT); - VMX_DBG_LOG(DBG_LEVEL_VMMU, "vmx_do_page_fault: pagetable = %lx\n", - pagetable_val(ed->arch.pagetable)); - - ed->arch.guest_pl2e_cache[index] = - mk_l2_pgentry((pfn << PAGE_SHIFT) | __PAGE_HYPERVISOR); - } - - if (unlikely(__get_user(gpte, (unsigned long *) - &linear_pg_table[va >> PAGE_SHIFT]))) + gpa = gva_to_gpa(va); + if (!gpa) return 0; - - gpa = (gpte & PAGE_MASK) | (va & (PAGE_SIZE - 1)); if (mmio_space(gpa)) - handle_mmio(va, gpte, gpa); + handle_mmio(va, gpa); if ((result = shadow_fault(va, error_code))) return result; @@ -299,35 +278,6 @@ static inline void guest_pl2e_cache_invalidate(struct exec_domain *ed) memset(ed->arch.guest_pl2e_cache, 0, PAGE_SIZE); } -inline unsigned long gva_to_gpa(unsigned long gva) -{ - unsigned long gpde, gpte, pfn, index; - struct exec_domain *ed = current; - - __guest_get_l2e(ed, gva, &gpde); - index = (gva >> L2_PAGETABLE_SHIFT); - - pfn = phys_to_machine_mapping(gpde >> PAGE_SHIFT); - - ed->arch.guest_pl2e_cache[index] = - mk_l2_pgentry((pfn << PAGE_SHIFT) | __PAGE_HYPERVISOR); - - if ( unlikely(__get_user(gpte, (unsigned long *) - &linear_pg_table[gva >> PAGE_SHIFT])) ) - { - printk("gva_to_gpa EXIT: read gpte faulted" ); - return 0; - } - - if ( !(gpte & _PAGE_PRESENT) ) - { - printk("gva_to_gpa - EXIT: gpte not present (%lx)",gpte ); - return 0; - } - - return (gpte & PAGE_MASK) + (gva & ~PAGE_MASK); -} - static void vmx_io_instruction(struct xen_regs *regs, unsigned long exit_qualification, unsigned long inst_len) { diff --git a/xen/arch/x86/vmx_platform.c b/xen/arch/x86/vmx_platform.c index 284243eca1..2f4d4ed21a 100644 --- a/xen/arch/x86/vmx_platform.c +++ b/xen/arch/x86/vmx_platform.c @@ -378,12 +378,7 @@ static int inst_copy_from_guest(char *buf, unsigned long guest_eip, int inst_len } if ((guest_eip & PAGE_MASK) == ((guest_eip + inst_len) & PAGE_MASK)) { - if ( unlikely(__get_user(gpte, (unsigned long *) - &linear_pg_table[guest_eip >> PAGE_SHIFT])) ) - { - printk("inst_copy_from_guest- EXIT: read gpte faulted" ); - return 0; - } + gpte = gva_to_gpte(guest_eip); mfn = phys_to_machine_mapping(gpte >> PAGE_SHIFT); ma = (mfn << PAGE_SHIFT) | (guest_eip & (PAGE_SIZE - 1)); inst_start = (unsigned char *)map_domain_mem(ma); @@ -392,6 +387,7 @@ static int inst_copy_from_guest(char *buf, unsigned long guest_eip, int inst_len unmap_domain_mem(inst_start); } else { // Todo: In two page frames + BUG(); } return inst_len; @@ -432,7 +428,6 @@ static void send_mmio_req(unsigned long gpa, ioreq_t *p; struct mi_per_cpu_info *mpci_p; struct xen_regs *inst_decoder_regs; - extern inline unsigned long gva_to_gpa(unsigned long gva); extern long evtchn_send(int lport); extern long do_block(void); @@ -476,7 +471,7 @@ static void send_mmio_req(unsigned long gpa, } -void handle_mmio(unsigned long va, unsigned long gpte, unsigned long gpa) +void handle_mmio(unsigned long va, unsigned long gpa) { unsigned long eip; unsigned long inst_len; diff --git a/xen/include/asm-x86/shadow.h b/xen/include/asm-x86/shadow.h index f5bc010415..15858d5901 100644 --- a/xen/include/asm-x86/shadow.h +++ b/xen/include/asm-x86/shadow.h @@ -684,6 +684,41 @@ static inline void vmx_update_shadow_state( unmap_domain_mem(mpl2e); } +static inline unsigned long gva_to_gpte(unsigned long gva) +{ + unsigned long gpde, gpte, pfn, index; + struct exec_domain *ed = current; + + __guest_get_l2e(ed, gva, &gpde); + if (!(gpde & _PAGE_PRESENT)) + return 0; + + index = (gva >> L2_PAGETABLE_SHIFT); + + if (!l2_pgentry_val(ed->arch.guest_pl2e_cache[index])) { + pfn = phys_to_machine_mapping(gpde >> PAGE_SHIFT); + ed->arch.guest_pl2e_cache[index] = + mk_l2_pgentry((pfn << PAGE_SHIFT) | __PAGE_HYPERVISOR); + } + + if ( unlikely(__get_user(gpte, (unsigned long *) + &linear_pg_table[gva >> PAGE_SHIFT])) ) + return 0; + + return gpte; +} + +static inline unsigned long gva_to_gpa(unsigned long gva) +{ + unsigned long gpte; + + gpte = gva_to_gpte(gva); + if ( !(gpte & _PAGE_PRESENT) ) + return 0; + + return (gpte & PAGE_MASK) + (gva & ~PAGE_MASK); +} + #endif /* CONFIG_VMX */ static inline void __shadow_mk_pagetable(struct exec_domain *ed) diff --git a/xen/include/asm-x86/vmx_platform.h b/xen/include/asm-x86/vmx_platform.h index 63cb74d90f..83cbb59e6f 100644 --- a/xen/include/asm-x86/vmx_platform.h +++ b/xen/include/asm-x86/vmx_platform.h @@ -86,7 +86,7 @@ struct virutal_platform_def { struct mi_per_cpu_info mpci; /* MMIO */ }; -extern void handle_mmio(unsigned long, unsigned long, unsigned long); +extern void handle_mmio(unsigned long, unsigned long); extern int vmx_setup_platform(struct exec_domain *, execution_context_t *); static inline int mmio_space(unsigned long gpa) -- 2.30.2